from gi.repository import Unity, Gio, GObject, Dbusmenu
import sys
import os
import thread
import time
from threading import Thread

class Loop(Thread):
    def __init__(self):
        Thread.__init__(self)
        self.loop = GObject.MainLoop()
    def run(self):
        GObject.threads_init()
        self.loop.run()
count = 0
if __name__ == '__main__':
    loop = Loop()
    def update_urgency(launcher):
        launcher.set_property('urgent', not launcher.get_property('urgent'))
        return True
    def update_count(launcher):
        launcher.set_property('count', launcher.get_property('count') + 1)
        return True
    def create_launcher(id):
        launcher = Unity.LauncherEntry.get_for_desktop_id(id)
        quicklist = Dbusmenu.Menuitem.new()
        item1 = Dbusmenu.Menuitem.new()
        item1.property_set('label', 'Item !!!')
        for i in range(10):
            item = Dbusmenu.Menuitem.new()
            item.property_set('label', 'Item ' + str(i))
            quicklist.child_append(item)
        launcher.set_property('quicklist', quicklist)
        #quicklist.child_set(0,item1)
        
        print dir(quicklist)
        #print quicklist.get_position(1)
        return launcher
    def update():
        update_urgency(kadu)
        update_count(eclipse)
        return True
    def idle(i):
        for i in range(100):
            update()
            time.sleep(1)
    
    kadu = create_launcher('kadu.desktop')
    print "done ;)"
    kadu.set_property('urgent', True)
    
    eclipse = create_launcher('Eclipse.desktop')
    print "done ;)"
    eclipse.set_property('count-visible', True)
    
    loop.start()
    
#    GObject.timeout_add_seconds(2, update_urgency, kadu)
#    GObject.timeout_add_seconds(1, update_count, eclipse)

    #GObject.idle_add(update)
#    GObject.idle_add(update)
#    GObject.idle_add(update)
        
    
#    GObject.MainLoop().run()
def set_property_bool(launcher, name, value):
    GObject.new_signal('set_property', Unity.LauncherEntry, GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, ())
